// view/index/bossxq/bossxq.js
let app = getApp()
let yuming = app.globalData.yuming
var lastFrameTime = 0;
var count = 0;
var ctx = null;
var factor = {
  speed: .008, // 运动速度，值越小越慢
  t: 0 //  贝塞尔函数系数
};
var that;
var timer = null; // 循环定时器
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({
  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    buttonClicked: false,
    yuming: yuming,
    heights: "",
    title: '老板圈',
    weidian: false,
    focusInput: false,
    height: 0,
    isInput: false,
    wen: '',
    pl: [], //该详情的评论列表
    pls: [],
    id: '', //id
    ids: '', //回复谁的id
    pae: 1,
    total: '', //评论数
    fid: '', //0评论 1回复
    fbnr: '', //获取发布内容
    shopId: wx.getStorageSync('shopId'),
    page: 1
  },
  // 详情
  xq() {
    // wx.showLoading({
    //   title: '加载中',
    //   icon:'none',
    // })
    var that = this
    this.myRequest(yuming + 'shop/shopFindBossCircle', {
      shopId: wx.getStorageSync('shopId'),
      id: that.data.id
    }, 'POST').then(res => {
      wx.hideLoading({})
      that.setData({
        xiao: res.data.data
      })
      if (this.data.xiao.shopLogo == null) {
        this.data.xiao.shopLogo = '../../images/mrtx.png'
      }
      this.setData({
        xiao: this.data.xiao
      })
      that.plxq()
    })
  },
  // 点赞
  dianzan(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    this.myRequest(yuming + 'shop/shopPubBossCircle', {
      shopId: wx.getStorageSync('shopId'),
      id: id
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        that.xq();
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
  // 点赞
  dianzans(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    this.myRequest(yuming + 'shop/shopPubBossCment', {
      shopId: wx.getStorageSync('shopId'),
      id: id
    }, 'POST').then(res => {
      // wx.showToast({
      //   title: res.data.msg,
      //   icon:'none'
      // })
      // setTimeout(function(){
      that.xq()
      // },1000)
    })
  },
  // 关注
  yiguan(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    console.log(e)
    this.myRequest(yuming + 'shop/shopAddBossfollow', {
      shopId: wx.getStorageSync('shopId'),
      fid: id
    }, 'POST').then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      that.xq()
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.pl
    this.setData({
      page: (this.data.page) + 1
    })
    this.plxq()
  },
  // 评论详情
  plxq() {
    var that = this
    this.myRequest(yuming + 'shop/shopSelectBossCment', {
      shopId: wx.getStorageSync('shopId'),
      id: that.data.id,
      page: that.data.page
    }, 'POST').then(res => {
      shu = res.data.data
      if (that.data.page != 1) {
        if (shu.length == 0) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          that.setData({
            pl: []
          })
        }
      }
      that.setData({
        pl: shuzong.concat(shu),
        total: res.data.total
      })
    })
  },
  inputFocus(e) {
    this.setData({
      height: e.detail.height
    })
    var that = this
    // setTimeout(function() {
    that.setData({
      isInput: true,
      focusInput: true,
    })
    // },1500)
  },
  inputBlur(e) {
    this.setData({
      isInput: false,
      focusInput: false,
      height: 0
    })
  },
  // 评论
  focusButn: function (e) {
    var fid = e.currentTarget.dataset.fid
    this.setData({
      focusInput: true,
      isInput: true,
      fbnr: '',
      fid: fid,
    })
  },
  // 回复
  huifu(e) {
    var fid = e.currentTarget.dataset.fid
    this.setData({
      focusInput: true,
      isInput: true,
      fbnr: '',
      fid: fid,
    })
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  fbnr(e) {
    this.setData({
      fbnr: e.detail.value
    })
  },
  // 敏感词过滤
  guolv() {
    let that = this;
    this.myRequest(yuming + 'Besall/mesg_sec_cheack', {
      content: that.data.fbnr
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        this.yanzheng(res.data.data)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
  // 敏感词验证
  yanzheng(content) {
    let that = this;
    this.myRequest(yuming + 'Besall/msg_sec_check', {
      from: 'EabEnd',
      content
    }, 'POST').then(res => {
      console.log(res);
      if (res.data.code == 200) {
        this.fasong(content);
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
  // 发送
  fasong(content) {
    var bcId = ''
    var that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'shop/shopAddBossCment', {
      shopId: wx.getStorageSync('shopId'),
      fid: that.data.fid,
      bcId: that.data.id,
      bcCment: content
    }, 'POST').then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        that.setData({
          isInput: false,
          fbnr: ''
        })
        setTimeout(function () {
          that.xq()
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }

    })
  },
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      id: options.id
    })
    that = this
    //获取canvas实例
    ctx = wx.createCanvasContext('mycanvas')
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      shopId: wx.getStorageSync('shopId')
    })
    this.xq()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if (timer != null) {
      clearTimeout(timer)
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})